package com.situ.mall.admin.service.impl;

import com.situ.mall.admin.service.IStatisticsService;
import com.situ.mall.base.entity.OrderInfo;
import com.situ.mall.base.mapper.OrderInfoMapper;
import com.situ.mall.base.vo.CountVO;
import com.situ.mall.base.mapper.CategoryMapper;
import com.situ.mall.base.mapper.MemberMapper;
import com.situ.mall.base.mapper.ProductMapper;
import com.situ.mall.base.util.C;
import com.situ.mall.base.util.URLUtil;
import com.situ.mall.base.vo.ResVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: StatisticsImpl
 * Package: com.situ.mall.admin.service.impl
 * Description:
 *
 * @Author Darling_达
 * @Create 2023-03-24 16:09
 * @Version 1.0
 */

@Service
public class StatisticsServiceImpl implements IStatisticsService {


    @Resource
    private MemberMapper memberMapper;

    @Resource
    private ProductMapper productMapper;

    @Resource
    private CategoryMapper categoryMapper;

    @Autowired
    private OrderInfoMapper orderInfoMapper;



    @Override
    public List<CountVO> statisticMemberByMonth() {
        return memberMapper.statisticMemberByMonth();
    }

    @Override
    public List<CountVO> statisticMemberByYear() {
        return memberMapper.statisticMemberByYear();
    }

    @Override
    public ResVO statistics() {
        ResVO vo = new ResVO();
        // 已注册会员的统计
        Map<String, Long> map = new HashMap<>();
        map.put(URLUtil.MEMBER_HTML + C.COUNT, memberMapper.statistics());
        // 统计订单总数
        map.put(URLUtil.ORDER_HTML + C.COUNT, orderInfoMapper.statistics());
        // 已上架商品的统计
        map.put(URLUtil.PRODUCT_HTML + C.COUNT + C.START, productMapper.statistics(1));
        // 已商品种类的统计
        map.put(URLUtil.CATEGORY_HTML + C.COUNT, categoryMapper.statistics());
        vo.setData(map);
        return vo;
    }

}
